import React from 'react';
import { Icon, Item } from 'semantic-ui-react'
import { withRouter } from 'react-router-dom'
import axios from 'axios'

class List extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            name:'',
            type:'',
            list:[]
        }
    }
    render(){
        let listInfo = this.state.list.map(item=>{
            return (
                <Item key={item.id}>
                <Item.Image size='tiny' src={'http://47.96.21.88:8086/public/home.png'} />     
                <Item.Content>
                  <Item.Header as='a'>{item.home_name}</Item.Header>
                  <Item.Meta>
                      <span className="cinema">{item.home_desc}</span>
                  </Item.Meta>
                  <Item.Description>
                    {item.home_tags}
                  </Item.Description>
                  <Item.Description>
                    {item.home_price}
                  </Item.Description>
                </Item.Content>
              </Item>
            );
        })
        return(
           <div className="house-list">
            <div className="house-list-title">
                <Icon onClick={this.goBack} name="angle left" size="large"></Icon>
                {this.state.name}
            </div>
            <div className="house-list-content">
                {/* 房源列表 */}
                <Item.Group divided unstackable>
                    {listInfo}
                </Item.Group>
            </div>
           </div>
        );
    }
    goBack = ()=>{
        let { history } = this.props
        history.goBack()
    }
    componentDidMount(){
        this.setState({
            name:this.props.location.state.mname,
            type:this.props.location.state.type,
        },()=>{
            axios.post('/homes/list',{
                home_type:this.state.type
            }).then(res=>{
                this.setState({
                    list:res.data
                })
            })
        })
    }
}

export default withRouter(List)